#!/bin/bash
script_dir=$(cd "$(dirname "$0")"; pwd)
build_dir=$script_dir/deploy

build_type=$1
if [ -z "$build_type" ]; then
    build_type="Release"
fi

if [ -z "${ACIS_ROOT}"] ; then 
    export ACIS_ROOT=/home/jason/workspace/amcax_interop/3rd/acis
fi

if [ -z "${INTEROP_ROOT}"] ; then 
    export INTEROP_ROOT=/home/jason/workspace/amcax_interop/3rd/interOp
fi

if [ -z "${INTEROP_LIBRARY_ZIP_DIR}"] ; then 
    export INTEROP_LIBRARY_ZIP_DIR=/home/jason/tools/temp
fi 

if [ -z "${INTEROP_BIN_ROOT}"] ; then 
    export INTEROP_BIN_ROOT=/home/jason/workspace/amcax_interop/deploy/install/Release
    export INTEROP_BIN=/home/jason/workspace/amcax_interop/deploy/install/Release/lib
fi 

if [ -z "${DATAKIT_BIN_ROOT}"] ; then 
    export DATAKIT_BIN_ROOT=/home/jason/workspace/amcaxdatakit/deploy/install/Release
    export DATAKIT_BIN=/home/jason/workspace/amcaxdatakit/deploy/install/Release/lib
fi 

if [ -z "${AMCAX_PATH}"] ; then 
    export AMCAX_PATH=/home/jason/tools/amcax
fi


export LD_LIBRARY_PATH=${ACIS_ROOT}/linux_a64/code/bin:${INTEROP_ROOT}/linux_a64/code/bin::${DATAKIT_ROOT}/linux_a64/code/bin:${env:LD_LIBRARY_PATH}

rm -rf ${build_dir}
# bash setup.sh $build_type

cmake -DCMAKE_BUILD_TYPE:STRING=$build_type  -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DInterOp=on -DAMXStorage=on -DAMCAXObj=on  --no-warn-unused-cli -S$script_dir -B$build_dir

cmake  --build $build_dir --config $build_dir  -j20 
# bash start.sh
# exit 0 

cmake  --install $build_dir  --strip --config $build_dir


now=$(date +"%Y%m%d%H%M%S")
glibc_version=$(ldd --version | head -n1 | awk '{print $NF}')
gcc_version=$(gcc --version | head -n1 | awk '{print $3}')
echo "GCC version: $gcc_version"
artifact_path="ExchangeSDK"_GLIBC_"$glibc_version""_GCC_$gcc_version""_"$now.tar.xz
cd $build_dir/install
tar -cvJf $artifact_path $build_type

